<?php 
defined('IN_TS') or die('Access Denied.'); 

function newtopic(){
	global $db;
	//最新话题
	$arrTopics = aac('group')->findAll('group_topic',array(
		'isaudit'=>0,
	),'uptime desc','topicid,userid,groupid,title,count_comment,uptime',10);
	if( $GLOBALS['TS_USER']!=''){
		$mylink = '&link='.$GLOBALS['TS_USER']['userid'];
	}

	if (count($arrTopics) > 0) {
		$groupids = array_column($arrTopics, "groupid");
		$groups = aac('group')->getGroups($groupids);

		$userids = array_column($arrTopics, "userid");
		$users = aac('user')->getUsers($userids);
	}


	foreach($arrTopics as $key=>$item){
			$arrTopic[] = $item;
			$arrTopic[$key]['title']=tsTitle($item['title']);
			$arrTopic[$key]['user'] = $users[$item["userid"]];
			$arrTopic[$key]['group'] = $groups[$item['groupid']]; 
	}
	
	
	
	include template('newtopic','newtopic');
	
}

function newtopic_css(){

	echo '<link href="'.SITE_URL.'plugins/home/newtopic/style.css" rel="stylesheet" type="text/css" />';

}

addAction('home_index_right','newtopic');
addAction('pub_header_top','newtopic_css');